package com.dxg.provider.token;

import java.util.Collection;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

/**
 * @author dingxigui
 * @version 1.0
 * @date 2021/7/30 11:13
 *
 *  请参考这2个token的描写
 * {@link UsernamePasswordAuthenticationToken}
 * {@link RememberMeAuthenticationToken}
 */
public class SmsAuthenticationToken extends AbstractAuthenticationToken {

  /**
   * 用户名
   */
  private final Object principal;

  /**
   * 密码
   */
  private Object credentials;

  public SmsAuthenticationToken(Object principal, Object credentials){
    super(null);
    this.principal = principal;
    this.credentials = credentials;
    //未认证过
    setAuthenticated(false);
  }

  public SmsAuthenticationToken(Object principal, Object credentials,
      Collection<? extends GrantedAuthority> authorities){
    super(authorities);
    this.principal = principal;
    this.credentials = credentials;
    //已经认证过
    super.setAuthenticated(true);
  }

  @Override
  public Object getCredentials() {
    return this.credentials;
  }

  @Override
  public Object getPrincipal() {
    return this.principal;
  }
}
